#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
using namespace std;
#include<vector>
#include<string>

class Solution1 {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int n = nums.size();
        int sum = 0, ret = INT_MAX;
        for (int left = 0, right = 0; right < n; right++)
        {
            sum += nums[right];
            while (sum >= target)
            {
                sum -= nums[left];
                ret = min(ret, right - left + 1);
                left++;

            }
        }
        return ret == INT_MAX ? 0 : ret;
    }
};

class Solution2 {
public:
    int lengthOfLongestSubstring(string s) {
        int n = s.size();
        int hash[128] = { 0 };
        int ret = 0;
        for (int left = 0, right = 0; right < n; right++)
        {
            hash[s[right]]++;
            while (hash[s[right]] > 1)
            {
                hash[s[left]]--;
                left++;
            }
            ret = max(ret, right - left + 1);

        }
        return ret;
    }
};

class Solution3 {
public:
    int longestOnes(vector<int>& nums, int k) {
        int n = nums.size(), zero = 0;
        int ret = 0;
        for (int left = 0, right = 0; right < n; right++)
        {
            if (nums[right] == 0)
            {
                zero++;
            }
            while (zero > k)
            {
                if (nums[left] == 0)
                    zero--;
                left++;
            }
            ret = max(ret, right - left + 1);
        }

        return ret;
    }
};

class Solution4 {
public:
    int minOperations(vector<int>& nums, int x) {
        int n = nums.size(), sum = 0, ret = -1;
        for (auto a : nums)
            sum += a;
        int target = sum - x, tmp = 0;
        if (target < 0) return -1;
        for (int left = 0, right = 0; right < n; right++)
        {
            tmp += nums[right];
            while (tmp > target)
            {
                tmp -= nums[left];
                left++;
            }
            if (tmp == target)
                ret = max(ret, right - left + 1);
        }
        if (ret == -1) return -1;
        return n - ret;
    }
};

int main()
{
    string s = " ";
    Solution2 a;
    int len = 0;
    len= a.lengthOfLongestSubstring(s);
    cout << len << endl;
    return 0;
}